using System;
using System.Threading.Tasks;
using FytSoa.Common.Utils;
using Quartz;
using Xunit;

namespace FytSoa.Quartz.Xunit
{
    public class UnitTest1
    {
        [Fact]
        public void Init()
        {
            var jobKey = new JobKey("test","taskGroup");
            var trigger = TriggerBuilder.Create()
                .WithDescription("触发器描述")
                .WithIdentity("test")
                //.WithSchedule(CronScheduleBuilder.CronSchedule("0 0/30 * * * ? *").WithMisfireHandlingInstructionDoNothing())
                .WithSimpleSchedule(x=>x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionIgnoreMisfires())
                .Build();
            QuartzService.Instance.Add(typeof(MyJob), jobKey, trigger);
        }
    }
    
    /// <summary>
    /// 测试任务
    /// </summary>
    public class MyJob : IJob
    {
        public Task Execute(IJobExecutionContext context)
        {
            return Task.Run(() =>
            {
                Logger.Info("执行MyJob"+DateTime.Now);
            });
        }
    }
}